<?php
/**
 * 获取软件版本更新接口
 * 验证用户身份token
 * @author Edwin
 */

namespace V1\Controller;

use Common\Controller\ApiController;

class UpdateController extends ApiController
{
    public function _initialize()
    {

    }

    public function rest()
    {
        switch ($this->_method) {
            case 'get': // get请求处理代码
                $this->_getVersion();
                break;
        }
    }

    /**
     * 通过端类型获取版本更新
     * @return mixed
     */
    private function _getVersion()
    {
        $type = I('get.type');
        $field = intval($type) == 1 ? ['version,intro'] : ['version,url,intro'];
        $version = M('version')->where('id=' . $type)->field($field)->find();
        if (!$version) {
            $this->myApiPrint(C('STATUS')['230'], 201, []);
        } else {
            $this->myApiPrint(C('STATUS')['200'], 200, $version);
        }
    }
}
